package com.itacademy.cinnamonreader.fragments;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.support.v4.app.FragmentActivity;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.itacademy.cinnamonreader.R;

public class MyAdapterHelper {
	 final String ATTRIBUTE_NAME_TEXT = "text";
	 final String ATTRIBUTE_NAME_IMAGE = "image";
	 public MyAdapterHelper(FragmentActivity activity, ListView listview, String data[],int img ){
			ArrayList<Map<String, Object>> feed = new ArrayList<Map<String, Object>>(
		            data.length);
		    Map<String, Object> m;
		    for (int i = 0; i < data.length; i++) {
		      m = new HashMap<String, Object>();
		      m.put(ATTRIBUTE_NAME_TEXT, data[i]);
		      m.put(ATTRIBUTE_NAME_IMAGE, img);
		      feed.add(m);
		    }
		    String[] from = { ATTRIBUTE_NAME_TEXT, ATTRIBUTE_NAME_IMAGE };
		    int[] to = { R.id.tvText, R.id.ivImg };
		    SimpleAdapter adapter = new SimpleAdapter(activity, feed, R.layout.feed_item, from, to);
		    listview.setAdapter(adapter); 
	 }

}
